import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main2 {

    public static int n;
    public static List<Long> list;
    public static int[] arr;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        while (t > 0) {
            t--;
            n = sc.nextInt();
            arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }

            for (int i = 0; i < n; i++) { //隔板数 0 - n-1
                boolean[] flag = new boolean[n - 1]; //是否插入隔板
                list = new ArrayList<>();
                dfs(i, flag, 0);
                long ret = Integer.MIN_VALUE;
                for (long num : list) {
                    ret = Math.max(num, ret);
                }
                System.out.print(ret + " ");
            }

            System.out.println();
        }

        sc.close();
    }

    /**
     *
     * @param k
     * @param flag
     * @param index 下一次插入隔板的下标
     */
    public static void dfs(int k, boolean[] flag, int index) {
        if (k == 0) {
            long sum = 0;
            int count = 1;
            long ret = 0;
            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    sum += arr[i];
                } else {
                    if (!flag[i - 1]) {
                        sum += arr[i];
                    } else {
                        ret += count * sum;
                        sum = arr[i];
                        count++;
                    }
                }
            }
            ret += count * sum;
            list.add(ret);
            return;
        }

        for (int i = index; i < n -1; i++) {
            //插
            flag[i] = true;
            dfs(k - 1, flag, i + 1);
            //回溯
            flag[i] = false;

            //不插
            dfs(k, flag, i + 1);
        }
    }
}
